package com.rfid.project.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rfid.project.model.People;
import com.rfid.project.model.Project;
import com.rfid.project.model.ProjectMemberType;
import com.rfid.project.model.ProjectTaskFinishApply;

@Service
@Transactional
public class ProcessSourceForProjectTaskFinishApply{

	@Autowired
	private ProjectTaskFinishApplyService projectTaskFinishApplyService;

	@Autowired
	private ProjectMemberService projectMemberService;

	@Autowired
	private PeopleService peopleService;
	
	public List<Process> getCurrentTaskListByProcessor(People people) {
		List<Process> resultList = new ArrayList<Process>();
		//找出当前用户负责的项目中的那些待审核任务完结申请
		Set<Project> projects = projectMemberService.findAllProjectByManager(people);

		List<ProjectTaskFinishApply> projectTaskFinishApplies = projectTaskFinishApplyService.findByStatus(people, ProjectMemberType.MANAGER, ProcessStatus.FINISH_APPLY);
		if (null != projectTaskFinishApplies && !projectTaskFinishApplies.isEmpty()) {
			for (ProjectTaskFinishApply apply : projectTaskFinishApplies) {
				boolean found = false;
				Project project = apply.getProjectTaskPerson().getProjectTask()
						.getProject();
				for (Project prj : projects) {
					if (project.getId().equals(prj.getId())) {
						found = true;
						break;
					}
				}
				if (found) {
					Process processTask = new Process();
					processTask.setBizId(apply.getId());
					processTask.setSubmitPerson(apply.getApplyPerson());
					processTask.setSubmitTime(apply.getApplyTime());
					processTask.setProcessStatusId(apply.getStatus());
					processTask
							.setProcessTypeId(ProcessType.PROJECT_TASK_FINISH);
					processTask.setProcessTitle(apply.getProjectTaskPerson()
							.getProjectTask().getProject().getName()
							+ "_"
							+ apply.getProjectTaskPerson().getProjectTask()
									.getTaskDescription() + "_申请完结!");
					resultList.add(processTask);
				}
			}
		}
		return resultList;
	}

	public List<Process> getCurrentTaskListByCreator(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Process> getHistoryTaskListByProcessor(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Process> getHistoryTaskListByCreator(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

}
